﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web;

namespace FileUploadASP
{
    /// <summary>
    /// Summary description for Handler1
    /// </summary>
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/png";
            string id = context.Request["id"];
            FileUploadEntities dbContext = new FileUploadEntities();
            Image i = (from ii in dbContext.Images
                       select ii).First();
            MemoryStream stream = new MemoryStream(i.FileBytes);

            context.Response.OutputStream.Write(i.FileBytes, 0, i.FileBytes.Length);
            //byte[] buffer = new byte[200];

            //int byteSeq = stream.Read(buffer, 0, 200);
            //while (byteSeq > 0)
            //{
            //    context.Response.OutputStream.Write(buffer, 0, byteSeq);
            //    Thread.Sleep(1000);
            //    byteSeq = stream.Read(buffer, 0, 200);
            //}
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}